<template>
  <ElSelect v-model="data" multiple>
    <ElOption v-for="(column, columnName) in seed.columns" :label="column.label" :value="columnName" :key="columnName" />
  </ElSelect>
</template>
<script setup lang="ts">
  import { getSeed } from '@/views/seed-dev';
  import { ElOption, ElSelect } from 'element-plus';
  import { ref, watch, watchEffect } from 'vue';

  const props = defineProps<{seedName: string, modelValue?: string}>()
  const emits = defineEmits(['update:modelValue'])

  const seed = getSeed(props.seedName)

  function getInitData() {
    if(!props.modelValue) return []

    return props.modelValue.split(',').map(e => e.trim())
  }
  const data = ref<string[]>(getInitData())

  watchEffect(() => emits('update:modelValue', data.value.join(',')))
  watch([() => props.seedName, () => props.modelValue], () => data.value = getInitData())
</script>